package cs236369.hw5.db;

import java.util.Collection;

import cs236369.hw5.db.beans.DbMessage;
import cs236369.hw5.db.beans.DbUser;

/**
 * this interface represents our connection to the db.
 *
 */
public interface DbHandler
{
	/**
	 * checks that the user doesn't exists, and if it doesn't saves it to the db.
	 * @param user is the user to add.
	 * @throws Exception
	 */
	public void saveNewUser(DbUser user) throws Exception;
	
	public void save(DbBean o) throws Exception;
	
	public void saveOrUpdate(DbBean o) throws Exception;
	
	/**
	 * it will load the msgs users, and event, <br>
	 * other lazy loading fields are not available.
	 * 
	 * @return {{@link Collection} of all the messages,<br>
	 *         empty collection if nothing found,<br>
	 *         null on error.
	 */
	public Collection<DbMessage> getMessagesForPresenting();

	
	/**
	 * find all the messages (event + post) which their distance from p is less than r.
	 * @param x 
	 * @param y
	 * @param d is the radius which represents the distance, (in WGS84 and not meters) 
	 * @return list of all the messages
	 */
	Collection<DbMessage> find(double x, double y, double d);

	/**
	 * get the user for profile presenting, load all lazy things...
	 * @param userName is the username
	 * @return the user, or null on error/ non-existing...
	 */
	public DbUser getUserProfile(String userName);

	/**
	 * register the user with the username to the event with the eventId.
	 * @param username is the user username.
	 * @param eventId is the event id.
	 * @return true on success(even if the user was not registered on the 1st place) , false otherwise
	 */
	public boolean registerEvent(String username, Long eventId);

	public boolean unRegisterEvent(String username, Long eventId);

	public void deleteUserMessage(String username, Long msgId);

	public void deleteUser(String username);

	
	
	

}
